/*
 * TCCSystemUserDAO.java
 *
 * Created on August 27, 2007, 9:58 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package tcc.dao.login;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Query;
import tcc.dao.AbstractDao;
import tcc.dao.Criteria;
import tcc.domain.login.TCCSystemUser;
import tcc.util.PersistenceUtil;


public class TCCSystemUserDAO extends AbstractDao{
    
    /** Creates a new instance of TCCSystemUserDAO */
    public TCCSystemUserDAO() {
    }

    public void delete(TCCSystemUser o) {
        o = findById(o.getId());
        super.delete(o);
    }

    public List<TCCSystemUser> findAll() {
        return super.find(TCCSystemUser.class,null);
    }

    public TCCSystemUser findByLogin(String login) {
        try{
            String queryString = new StringBuilder("from ")
                    .append(TCCSystemUser.class.getName())
                    .append(" where ")
                    .append(" login = :login").toString();
            Query q =  PersistenceUtil.getInstance().getEntityManager().createQuery(queryString);
            q.setParameter("login", login);
            return (TCCSystemUser) q.getSingleResult();    
        }catch(javax.persistence.NoResultException ex){
            return null;
        }
    }
    
    public TCCSystemUser findById(Long id) {
        return  super.findById(TCCSystemUser.class,id);
    }

    public void save(TCCSystemUser o) {
       super.save(o);
    }    
}
